{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "cve_str = \"\"\"CVE-2022-48908\n",
    "CVE-2022-48909\n",
    "CVE-2022-48911\n",
    "CVE-2023-52907\n",
    "CVE-2021-4442\n",
    "CVE-2023-52899\n",
    "CVE-2023-52900\n",
    "CVE-2023-52903\n",
    "CVE-2023-52906\n",
    "CVE-2024-46725\n",
    "CVE-2024-46737\n",
    "CVE-2024-46738\n",
    "CVE-2024-46739\n",
    "CVE-2024-46740\n",
    "CVE-2024-46791\n",
    "CVE-2024-46743\n",
    "CVE-2024-46747\n",
    "CVE-2021-47233\n",
    "CVE-2024-46678\n",
    "CVE-2024-46761\n",
    "CVE-2024-46756\n",
    "CVE-2024-46757\n",
    "CVE-2024-46758\n",
    "CVE-2024-46763\n",
    "CVE-2024-46770\n",
    "CVE-2024-46781\n",
    "CVE-2024-46782\n",
    "CVE-2024-46742\n",
    "CVE-2024-46726\n",
    "CVE-2024-46728\n",
    "CVE-2024-46731\n",
    "CVE-2024-46755\n",
    "CVE-2024-46765\n",
    "CVE-2024-42287\n",
    "CVE-2024-40973\n",
    "CVE-2022-48896\n",
    "CVE-2024-46677\n",
    "CVE-2024-46685\n",
    "CVE-2024-44940\n",
    "CVE-2022-48726\n",
    "CVE-2022-48749\n",
    "CVE-2021-47619\n",
    "CVE-2022-48723\n",
    "CVE-2021-47439\n",
    "CVE-2024-46723\n",
    "CVE-2024-46681\n",
    "CVE-2024-46707\n",
    "CVE-2024-46702\n",
    "CVE-2024-46695\n",
    "CVE-2024-46800\n",
    "CVE-2024-46719\n",
    "CVE-2024-46721\n",
    "CVE-2024-46722\n",
    "CVE-2024-46724\"\"\"\n",
    "cve_list = cve_str.strip().split(\"\\n\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests\n",
    "def branch_determine(cve_id):\n",
    "    _headers =  {\n",
    "    \"Cookie\" : \"token=BQCVAZJ6fPDSWPre8wJSRBTZ/k7/OgV5/ToFCdsFhlbcesn2O7JImDxtvxMMgh3AQZeGCz9ksw9KvMa+q8yCyLWYib42jVRsiujuIj2/ScQazfaQ0gFFFGRIfaviHQQotbyZ9vOyfM/N3G8Nov/KfAl9cTo2h2BIJZT8MNOZCSkXOK8NZg5AmNau0pbvzaEjyK0D+xM/N7p39rGNWqao4fCbT2EeTOlK+nW8GkeQ0QTr6chIkMfF1pOoMkXtyFhDirafcIP/pfSq1mGm4c+IQQ4By+niOURiP/bST1BJYU/UyQKPpSzgRUKMrnoFkoALzo9leHLOAIuJmzAhhTnldcWoBQCbtT0UzqBTTPSw6ZWLMqdL9ORbC+mNhxPzjtOwnAWdWv7aRs5Nxbi38NUJjl8Zj8SuptYcd/VcDUOMO8Faq9UnbHN4jAcUht6trrszpEwycTLXbozHfqO9LWX14ic3y+QNDaWJJk+X4qT7HZPbZjVhYzNkMjktODg1MC00MDNmLWE3NjgtMmJhMzhhMWRmYjViAAAAACMiISAfHh0cGxoZGBcWFRQTEhEQDw4NDAsKCQgHBgUEAwIBnu/TMdJR1Dj0+6fRpT3w58YiVhDh3lODkPZ8kTKMLvQ=; _frid=8a21010d7fed4ed2ab3bc98785758bc8; HWWAFSESID=0fc15768f23e744065; HWWAFSESTIME=1725516636873; _fr_ssid=f96a85c03bce4f8c9d2bb06d14512672; _fr_pvid=04ce5cbbefae42c084c0528dcd17dd26\"\n",
    "        }\n",
    "    # data不对的话 会提示service error\n",
    "    data = {\n",
    "        \"internalId\": None,\n",
    "        \"cveId\": cve_id,\n",
    "        \"repoName\": None,\n",
    "        \"versionNum\": None,\n",
    "        \"branch\": 'master',\n",
    "        \"influence\": None,\n",
    "        \"processStage\": None,\n",
    "        \"investigateTime\": None,\n",
    "        \"createTime\": None,\n",
    "        \"investigateOwner\": None,\n",
    "        \"startInvestigateTime\": None,\n",
    "        \"endInvestigateTime\": None,\n",
    "        \"startCreateTime\": None,\n",
    "        \"endCreateTime\": None,\n",
    "        \"updateTime\": None,\n",
    "        \"sortField\": \"\",\n",
    "        \"sortType\": \"DESC\",\n",
    "        \"type\": 0,\n",
    "        \"startExpirationDate\": None,\n",
    "        \"endExpirationDate\": None,\n",
    "        \"pageSize\": 10,\n",
    "        \"currentPage\": 1,\n",
    "        \"totalSize\": 3\n",
    "    }\n",
    "\n",
    "    resp = requests.post('https://ci.openharmony.cn/api/opensoftware/vulnerability/investigate/all', headers=_headers, json=data)\n",
    "    j = resp.json()\n",
    "    l = j['data']['dataList']\n",
    "    processStage = {0: '分支排查', 1: '漏洞修补', 2: '专家审核', 3: '已完成', 4: '挂起评审', 5: '已挂起'}\n",
    "    if (len(l) > 0):\n",
    "        for i in l:\n",
    "            return (processStage[i['processStage']])\n",
    "    else:\n",
    "        return \"待修复\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "误报，CONFIG_ARCNET_COM20020_PCI未开启 不涉及\n",
      "误报，CONFIG_SMC未开启 不涉及\n",
      "漏洞已修改，https://gitee.com/openharmony/kernel_linux_5.10/commit/1ffd27159d97dd08e135367848321450e030e8cf master/4.0/4.1\n",
      "误报，CONFIG_CONFIG_NFC_PN533_USB未开启不涉及\n",
      "\n",
      "误报，CONFIG_DW_AXI_DMAC选项未开启，不涉及\n",
      "误报，CONFIG_NILFS2_FS选项没有开启，不涉及\n",
      "误报，CONFIG_IO_URING未开启 不涉及\n",
      "误报，CONFIG_NET_ACT_MPLS未开启 不涉及\n",
      "CVE-2024-46725 待修复\n",
      "CVE-2024-46737 待修复\n",
      "CVE-2024-46738 待修复\n",
      "CVE-2024-46739 待修复\n",
      "CVE-2024-46740 待修复\n",
      "CVE-2024-46791 待修复\n",
      "CVE-2024-46743 待修复\n",
      "CVE-2024-46747 待修复\n",
      "漏洞已修改，https://gitee.com/openharmony/kernel_linux_5.10/commit/ba8a26a7ce8617f9f3d6230de34b2302df086b41 master/3.2/4.0/4.1\n",
      "CVE-2024-46678 待修复\n",
      "CVE-2024-46761 待修复\n",
      "CVE-2024-46756 待修复\n",
      "CVE-2024-46757 待修复\n",
      "CVE-2024-46758 待修复\n",
      "CVE-2024-46763 待修复\n",
      "CVE-2024-46770 待修复\n",
      "CVE-2024-46781 待修复\n",
      "CVE-2024-46782 待修复\n",
      "CVE-2024-46742 待修复\n",
      "CVE-2024-46726 待修复\n",
      "CVE-2024-46728 待修复\n",
      "CVE-2024-46731 待修复\n",
      "CVE-2024-46755 待修复\n",
      "CVE-2024-46765 待修复\n",
      "误报，CONFIG_SCSI_QLA_FC选项未开启，不涉及\n",
      "漏洞已修改，https://gitee.com/openharmony/kernel_linux_5.10/commit/60116a296ba696aa085add7ca41ffb97a14fa4ad master/4.0/4.1\n",
      "CVE-2022-48896 待修复\n",
      "CVE-2024-46677 分支排查\n",
      "CVE-2024-46685 待修复\n",
      "误报，所修复问题在本分支未引入，不涉及该漏洞，暂不考虑修复\n",
      "误报，CONFIG_INFINIBAND_ADDR_TRANS未开启 不涉及\n",
      "CVE-2022-48749 已完成\n",
      "误报，CONFIG_I40E未开启 不涉及\n",
      "误报，CONFIG_SPI_UNIPHIER未开启 不涉及\n",
      "误报，CONFIG_NET_DSA_MICROCHIP_KSZ_COMMON 未开启 不涉及\n",
      "CVE-2024-46723 待修复\n",
      "CVE-2024-46681 待修复\n",
      "CVE-2024-46707 待修复\n",
      "CVE-2024-46702 待修复\n",
      "CVE-2024-46695 待修复\n",
      "CVE-2024-46800 分支排查\n",
      "CVE-2024-46719 待修复\n",
      "CVE-2024-46721 待修复\n",
      "CVE-2024-46722 待修复\n",
      "CVE-2024-46724 待修复\n"
     ]
    }
   ],
   "source": [
    "## CI\n",
    "import sys\n",
    "sys.path.append(\"../\")\n",
    "import service.AnalysisService as analysisService\n",
    "for cve_id in cve_list:\n",
    "    res = analysisService.analyzeCI(cve_id)\n",
    "    if '有效漏洞' in res:\n",
    "        print(cve_id, branch_determine(cve_id))\n",
    "        continue\n",
    "    print(res.replace(\"\\n\", \" \"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{0: '分支排查', 1: '漏洞修补', 2: '专家审核', 3: '已完成', 4: '挂起评审', 5: '已挂起'}\n"
     ]
    }
   ],
   "source": [
    "list = [{\n",
    "                            'label': \"分支排查\",\n",
    "                            'value': 0\n",
    "                        }, {\n",
    "                            'label': \"漏洞修补\",\n",
    "                            'value': 1\n",
    "                        }, {\n",
    "                            'label': \"专家审核\",\n",
    "                            'value': 2\n",
    "                        }, {\n",
    "                            'label': \"已完成\",\n",
    "                            'value': 3\n",
    "                        }, {\n",
    "                            'label': \"挂起评审\",\n",
    "                            'value': 4\n",
    "                        }, {\n",
    "                            'label': \"已挂起\",\n",
    "                            'value': 5\n",
    "                        }]\n",
    "d = dict()\n",
    "for item in list:\n",
    "    d[item['value']] = item['label']\n",
    "print(d)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
